package com.ims.controller;

import com.alibaba.fastjson.JSONObject;
import com.ims.pojo.Device;
import com.ims.service.DeviceService;
import com.ims.util.PageResult;
import com.ims.util.QueryPageBean;
import com.ims.util.Result;
import com.ims.util.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: zk
 * @date: 2022/9/4 15:40
 */
@RestController
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @PostMapping("/findPage")
    public Result<PageResult> findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult<JSONObject> pageResult = deviceService.findPage(queryPageBean);
        return new Result<>(true, StatusCode.OK, "分页查询成功", pageResult);
    }

    @PostMapping("/add")
    public Result<Device> add(@RequestBody Device device) {
        boolean addSuccess = deviceService.add(device);
        if (addSuccess) {
            return new Result<>(true, StatusCode.OK, "插入设备信息成功");
        } else {
            return new Result<>(false, StatusCode.ERROR, "插入设备信息失败");
        }
    }
}
